﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NLog;
using SP.DataExchange.BusMessage;
using SP.DataExchange.ServiceBus;

namespace SP.DataExchange.SubcribConsoleTest
{
    public class ServiceHandler
    {
        private IServiceBus _bus;
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        public bool Start()
        {
            _bus = new ServiceBus.ServiceBus();
            try
            {
                _bus.Subscribe<TestLogMessage>("", msg =>
                {
                    Debug.Print(msg.Name);
                    Logger.Info(msg.Name);
                });

                Logger.Error("服务已启动");
                return true;
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return false;
            }
        }

        public bool Stop()
        {
            _bus.Dispose();
            return true;
        }
    }
}
